package com.woniuxy.hrp.web.AdminController;

import com.woniuxy.hrp.entity.Department;
import com.woniuxy.hrp.service.DepartService;
import com.woniuxy.hrp.unityhandler.ResponseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * @program: hrph
 * @InterfaceName DepartmentController
 * @description:科室Controller
 * @author: WY
 **/
@Transactional
@RestController
@RequestMapping("/api/v1/admin/department")
public class DepartmentController {

    @Autowired
    private DepartService departService;

    //根据医院id(Hid为Hospitalid简写)查询所拥有的所有科室
    @RequestMapping("/list")
    public ResponseEntity list(int Hid){
        List<Department> departments = departService.findByHospitalId(Hid);
        return new ResponseEntity("200","OK",departments);
    }

    //根据科室id查询科室
    @GetMapping("/update")
    public ResponseEntity update(int id){
        Department department = departService.findById(id);
        return new ResponseEntity("200","OK",department);
    }
    //根据科室id修改科室信息
    @PostMapping("/update")
    public ResponseEntity updateinfo(@RequestBody Department department){
        departService.update(department);
        return ResponseEntity.SUCCESS;
    }

    //科室的增加
    @PostMapping("/add")
    public ResponseEntity add(@RequestBody Department department){
        departService.add(department);
        return new ResponseEntity("200","OK",null);
    }

}
